home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload Trio 2
/
Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO
/
dir27
/
calctool.zip
/
CALCTOOL.PS
< prev
next >
Wrap
Text File
|
1992-09-09
|
6KB
|
272 lines
% These are the NeWS dependent graphics routines used by calctool.
% They make use of the tnt toolkit distributed with OpenWindows.
%
% Copyright (c) Rich Burridge - Sun Microsystems, Australia.
% All rights reserved.
%
% @(#)calctool.ps 1.5 89/12/21
%
% Permission is given to distribute these sources, as long as the
% copyright messages are not removed, and no monies are exchanged.
%
% No responsibility is taken for any errors or inaccuracies inherent
% either to the comments or the code of this program, but if
% reported to me then an attempt will be made to fix them.
%
% Define a class for the main calctool window. The following events
% are handled:
%
% Left mouse button (down and up).
% Middle mouse button (down and up).
% Right mouse button (down and up).
% Keyboard press.
% Window damage.
%
% For each of these events, an appropriate tag is sent back to the C code.
/KeyClass ClassCanvas []
classbegin
/PaintCanvas
{
CFRAME_REPAINT typedprint
} def
/MakeInterests
{
/MakeInterests super send
LeftMouseButton {LEFT_DOWN SendEvent} /DownTransition self MakeInterest
MiddleMouseButton {MIDDLE_DOWN SendEvent} /DownTransition self MakeInterest
LeftMouseButton {LEFT_UP SendEvent} /UpTransition self MakeInterest
MiddleMouseButton {MIDDLE_UP SendEvent} /UpTransition self MakeInterest
{KbdEvent} Canvas /defaultkeys ClassKeysInterest send
} def
classend def
% Define a class for the memory register window.
% Handle window damage in the same way as the main calctool window.
/RegClass ClassCanvas []
classbegin
/PaintCanvas
{
RFRAME_REPAINT typedprint
} def
classend def
% Clear the whole of either the main calctool canvas or the memory
% register canvas to a specific color.
/PSClearCanvas % color canvas => -
{
dup setcanvas
ColorTable 3 -1 roll get
/fillcanvas 3 -1 roll send
} def
% Close the main calctool window and unmap the memory register window.
/PSCloseFrame % - => -
{
/flipiconic KFrame send
/unmap RFrame send
} def
% Color a rectangular area in the main calctool window.
/PSColorArea % color x width height y => -
{
KC setcanvas
KCHeight exch sub exch dup 3 1 roll sub 3 1 roll rectpath
ColorTable exch get setcolor
fill
} def
% Draw a line in the main calctool window.
/PSDrawLine % x1 x2 y1 y2 => -
{
KCHeight exch sub
exch KCHeight exch sub 3 1 roll
KC setcanvas
newpath
moveto lineto
0 setgray
stroke
} def
% Draw (map) the memory register window.
/PSDrawRegs
{
/map RFrame send
} def
% Load the small, normal and bold fonts used by calctool.
/PSInitFonts % - => -
{
/SFont /Courier findfont 10 scalefont def
/NFont /Courier-Bold findfont 14 scalefont def
/BFont /Courier-Bold findfont 18 scalefont def
} def
% Set up the various tags that are passed back to the C code.
% Note that at present, some of these tags are not used.
/PSInitialise % - => -
{
/CFRAME_REPAINT 100 def
/RFRAME_REPAINT 101 def
/ENTER_WINDOW 102 def
/EXIT_WINDOW 103 def
/KEYBOARD 104 def
/LEFT_DOWN 105 def
/LEFT_UP 106 def
/MIDDLE_DOWN 107 def
/MIDDLE_UP 108 def
/RIGHT_DOWN 109 def
/RIGHT_UP 110 def
/TAKE_FROM_SHELF 111 def
/PUT_ON_SHELF 112 def
} def
% Test if calctool is running on a color framebuffer.
/PSIsColor % - => iscolorscreen
{
/Color? framebuffer /Color get def
Color? {1} {0} ifelse typedprint
} def
% Load a red green blue triplet into the appropriate entry in the colortable.
/PSLoadColor % index blue green red => -
{
255 div
exch 255 div
3 -1 roll 255 div
rgbcolor
ColorTable 3 1 roll put
} def
% Create an array big enough for all the colors used by calctool.
/PSMakeColorTable % size => -
{
/ColorTable exch array def
} def
/KbdEvent
{
begin
Action /DownTransition eq
{
KEYBOARD typedprint Name SendEvent
} if
end
} def
/SendEvent
{
KC setcanvas
typedprint
currentcursorlocation KCHeight exch sub exch
typedprint typedprint
} def
/PaintIcon
{
clippath pathbbox
scale pop pop
0 setgray
false calctoolIcon imagemaskcanvas
} def
% Create the main calctool frame and the memory registers property sheet.
% Set the size of these items, and place the open frame and icon at the
% correct place.
/PSMakeFrames % wx wy width height ix iy iconic => -
{
[ /IsIcon /IconY /IconX /KCHeight /KCWidth /KCY /KCX ]
{ exch def } forall
% /ScreenHeight /size framebuffer send exch def pop
/ScreenHeight 900 def
/KFrame [KeyClass] [/Footer false /Label false]
framebuffer /new OpenLookBaseFrame send def
/KC /client KFrame send def
KCWidth KCHeight /lockminsize KC send
calctoolIcon /seticon KFrame send
% IconX
% ScreenHeight FrameHeight sub IconY sub
% 42 64 /reshape /Icon /sendsubframe KFrame send
/preferredsize KFrame send /FrameHeight exch def
/FrameWidth exch def
KCX
ScreenHeight FrameHeight sub KCY sub
FrameWidth FrameHeight /reshape KFrame send
/RFrame [RegClass] framebuffer /new OpenLookPropertyFrame send def
/RC /client RFrame send def
/RCHeight 200 def
KCWidth RCHeight /lockminsize RC send
/activate KFrame send
% /map IsIcon 1 eq {/Icon /subframes KFrame send get} {KFrame} ifelse send
% IsIcon 1 eq {/close KFrame send} if
/map KFrame send
/activate RFrame send
/place RFrame send
} def
% Place a colored text string in the appropriate font at the given
% x,y position in either the main calctool window or the memory
% register window.
/PSMakeText % string x canvasheight y font color canvas => -
{
setcanvas
ColorTable exch get setcolor
setfont
sub moveto show
} def
/PSSetCursor % type => -
{
} def
% Depending upon the current setting, either show (map) or remove
% (unmap) the memory register window.
/PSToggleRegCanvas % state => -
{
1 eq { /map RFrame send} { /unmap RFrame send} ifelse
} def